home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 4 / Mac Giga-ROM 4.0 - 1993.toast / FILES / DAS / R-T / SetSound / SetSound.asm next >
Encoding:
Assembly Source File  |  1986-01-04  |  6.4 KB  |  255 lines  |  [TEXT/Anon]

  1. ;-----------------------------------------------------------------------
  2. ; SetSound DA
  3. ; Copyright 1985 by William P. Steinberg
  4. ;
  5. ; SetSound is a small (0.6K) DA that sets the default sound volume
  6. ; Shrink & obscure courtesy Steve Brecher
  7. ; Original shell from MacUser issue #1, Bill Bond & Chris Allen
  8. ;
  9. ;---
  10. ; Version 1.0 = 1008 bytes
  11. ; Version 1.2 = 562 bytes
  12. ; Version 1.3 = put back autokey in accepted eventlist, though I ignore it
  13. ;-----------------------------------------------------------------------
  14.  
  15.     Resource 'DRVR' 31 'SetSound' 32
  16.  
  17.     INCLUDE    Sys.D
  18.  
  19.     Macro    Assume    Cond =
  20.     If    {Cond}
  21.     Else
  22.     Error -- Assumption {Cond} is not true
  23.     Endif
  24.     |
  25.  
  26. DAStart:
  27.     DC.W    $4400            ; Flags/descriptor
  28.                     ; (lock in memory, can respond to
  29.                     ; Control calls)
  30.     DC.W    0            ; Tick Count
  31.     DC.W    360            ; Event mask
  32.                     ; (will handle: keydown, autokey,
  33.                     ; mousedown, and activate)
  34.     DC.W    0            ; Menu ID
  35.     DC.W    DAOpen-DAStart        ; Offset to open routine
  36.     DC.W    DAPrime-DAStart        ; Offset to prime routine
  37.     DC.W    DAControl-DAStart    ; Offset to control routine
  38.     DC.W    DAStatus-DAStart    ; Offset to status routine
  39.     DC.W    DAClose-DAStart        ; Offset to close routine
  40.     DC.B    8            ; Desk Accesory title
  41.     DC.B    'SetSound'        ; (This is optional - it only helps
  42.     .ALIGN    2            ; to identify the DA in the heap.
  43.                     ; The DA appears in the Apple
  44.                     ; menu using the name of DRVR.)
  45.  
  46. ; A6 offsets:
  47. ;
  48. DriverID    EQU    -2        ; Word
  49. DriverType    EQU    DriverID-4    ; Long
  50. DriverName    EQU    DriverType-256    ; 256 byte string buffer
  51.  
  52. DAOpen:
  53.     LINK    A6,#DriverName
  54.     MOVE.L    (A5),A0            ; addr of QD globals
  55.     Assume    thePort = 0
  56.     MOVE.L    (A0),-(SP)        ; save thePort on stack
  57.     MOVE.L    A1,A4            ; Put DCE pointer in A4
  58.  
  59.     MOVEQ    #0,D3            ; assume already open, result = noErr
  60.     TST.L    dCtlWindow(A4)        ; Does the window exist ?
  61.     BNE.S    OpenDone        ; If yes, the DA was already opened
  62.  
  63.     LEA    DAStart,A0        ; Get handle to the DA
  64.     _RecoverHandle
  65.     MOVE.L    A0,-(SP)        ; Get information about DA
  66.     PEA    DriverID(A6)        ; DA id
  67.     PEA    DriverType(A6)        ; DA type = 'DRVR'
  68.     PEA    DriverName(A6)        ; DA name
  69.     _GetResInfo
  70.  
  71.     SUBQ    #4,SP            ; Make room for result
  72.     CLR.L    -(SP)            ; Create WindowRecord on the heap
  73.     PEA    WindowRect        ; Push the address of the window's rect
  74.     PEA    DriverName(A6)        ; Push the address of the window's title
  75.     CLR    -(SP)            ; Make it invisible for now
  76.     MOVE.W    #noGrowDocProc,-(SP)    ; Push the window definition id
  77.     MOVEQ    #-1,D0
  78.     MOVE.L    D0,-(SP)        ; Window will appear in front
  79.     MOVE.B    D0,-(SP)        ; Give it a goaway box
  80.     CLR.L    -(SP)            ; Window reference value
  81.     _NewWindow            ; Create the window
  82.     MOVEQ    #OpenErr,D3        ; assume failure
  83.     MOVE.L    (SP)+,D1        ; Get the window pointer
  84.     BEQ.S    OpenDone
  85.     LEA    MyWindow,A0
  86.     MOVE.L    D1,(A0)            ; Save the window pointer
  87.     MOVE.L    D1,A0
  88.     MOVE.W    dCtlRefNum(A4),windowKind(A0)
  89.     MOVE.L    A0,dCtlWindow(A4)    ; Put the window pointer in the DCE
  90.     MOVEQ    #0,D3            ; Result = noErr
  91. OpenDone:
  92.     _SetPort            ;restore thePort
  93.     UNLK    A6
  94.     MOVE.L    D3,D0
  95.     RTS
  96.  
  97. DAClose:
  98.     MOVE.L    A1,A4            ; Put Device Control Entry in A4
  99.     MOVE.L    (A5),A0            ;addr of QD globals
  100.     Assume    thePort = 0
  101.     MOVE.L    (A0),-(SP)        ;save thePort on stack
  102. CloseDA:
  103.  
  104.     MOVE.L    WindowList,D0
  105. DAClose1:
  106.     BEQ.S    DAClose3
  107.     CMP.L    MyWindow,D0        ; Is this our window ?
  108.     BEQ.S    DAClose2
  109.     MOVE.L    D0,A0
  110.     MOVE.L    nextWindow(A0),D0    ; Get the next window in the chain
  111.     BRA.S    DAClose1
  112. DAClose2:
  113.     MOVE.L    D0,-(SP)        ; Throw away our window
  114.     _DisposWindow
  115.     CLR.L    dCtlWindow(A4)        ; Window is gone, tell the DCE
  116. DAClose3:
  117.     _SetPort
  118.     Bra.S    DAexit
  119.  
  120. DAControl:
  121.     MOVE.L    A1,A4            ; Put pointer to DCE in A4
  122.     MOVE.L    (A5),A1            ;addr of QD globals
  123.     Assume    thePort = 0
  124.     MOVE.L    (A1),-(SP)        ;save thePort on stack
  125.  
  126.     ; A0 points to the parameter block which tells us what we need
  127.     ; to do and supplies us with the data to carry it out.
  128.  
  129.     MOVE    csCode(A0),D0
  130.  
  131.     Assume    GoodBye = -1
  132.     ADDQ    #1,D0
  133.     BEQ.S    CloseDA            ; bye
  134.     CMP.W    #accEvent+1,D0        ; Event message from SystemEvent
  135.     BNE.S    CTLReturn
  136.  
  137. CTLEvent:
  138.     LEA    SPVolCtl,A3        ;for later
  139.     MOVE.L    csParam(A0),A2
  140.     MOVE.L    MyWindow,-(SP)
  141.     _SetPort
  142.     Assume    evtNum = 0
  143.     CMP.W    #keyDwnEvt,(A2)        ; Keydown event
  144.     BEQ    EVTkeyDown
  145.     CMP.W    #updatEvt,(A2)        ; Update event
  146.     BEQ.S    EVTupdateEvt
  147.     CMP.W    #activateEvt,(A2)    ; Activate event
  148.     BEQ.S    EVTactivateEvt
  149. CTLReturn:
  150.     _SetPort
  151.     MOVE.L    A4,A1            ; restore DCE ptr
  152.     MOVE.L    JIODone,-(SP)        ; Goto IODone
  153. DAPrime:
  154. DAStatus:
  155. DAexit:
  156.     CLR.W    D0            ; Return code
  157.     RTS
  158.  
  159. EVTactivateEvt:
  160.     LEA    ActivePend,A0
  161.     MOVE.B    EvtMBut(A2),(A0)    ; Low order byte of EvtMeta
  162.     BRA.S    CTLReturn
  163.  
  164. EVTupdateEvt:
  165.     MOVE.L    MyWindow,A2
  166.     MOVE.L    A2,-(SP)        ; for EndUpdate
  167.     PEA    portRect(A2)        ; for EraseRect
  168.     MOVE.L    A2,-(SP)
  169.     _BeginUpdate
  170.     MOVE.B    (A3),D0            ; SPVolCtl
  171.     LEA    Chars,A2
  172.     AND.B    (A2)+,D0        ; (#7) clr bits 3..15
  173.     ADD.B    (A2)+,D0        ; (#'0') Convert to ASCII
  174.     LEA    ASCIIVol,A3
  175.     MOVE.B    D0,(A3)            ; set ASCII volume in message
  176.     _EraseRect
  177.     MOVE.W    (A2)+,-(SP)        ; space
  178.     _DrawChar
  179.     ST    -(SP)
  180.     _SetFontLock
  181.     LEA    Coords,A3
  182.     MOVE.L    (A3)+,-(SP)
  183.     _MoveTo
  184.     Assume    SysFont = 0
  185.     CLR.W    -(SP)
  186.     _TextFont
  187.     MOVE.W    (A2)+,-(SP)        ;Copyright symbol
  188.     _DrawChar
  189.     MOVE.W    #applFont,-(SP)
  190.     _TextFont
  191.     MOVEQ    #0,D4
  192.     MOVEQ    #4-1,D3
  193. @0    MOVE.L    A2,-(SP)        ;msg addr
  194.     _DrawString
  195.     MOVE.L    (A3)+,-(SP)        ;next coords (note we do one
  196.     _MoveTo                ;superfluous MoveTo)
  197.     MOVE.B    (A2)+,D4        ;bump to next msg...
  198.     ADD    D4,A2
  199.     DBRA    D3,@0
  200.     _EndUpdate
  201.     CLR    -(SP)
  202.     _SetFontLock
  203.     LEA    ActivePend,A2
  204.     BCLR    #ActiveFlag,(A2)
  205.     BEQ.S    CtlReturn
  206. Beep:    MOVE.W    #3,-(SP)        ; Beep on update at current level
  207.     _SysBeep
  208. CtlRet    BRA.S    CTLReturn
  209.  
  210. EVTkeyDown:
  211.     CLR    D2
  212.     MOVE.B    evtMessage+3(A2),D2
  213.     SUB.B    #'0',D2
  214.     BMI.S    CtlRet
  215.     CMP.B    #7,D2
  216.     BGT.S    CtlRet
  217.  
  218.     ANDI.B    #$F8,(A3)        ;SPCtlVol
  219.     OR.B    D2,(A3)
  220.     LINK    A1,#-(csParam+2)
  221.     MOVE.L    A1,A0
  222.     MOVE    D2,-(A0)        ;csParam
  223.     Assume    csCode = csParam-2
  224.     MOVE    #2,-(A0)        ;csCode
  225.     Assume    ioRefNum = csCode-2
  226.     MOVE.W    #-4,-(A0)        ;sound drvr refnum
  227.     MOVE.L    SP,A0
  228.     _Control,IMMED
  229.     UNLK    A1
  230.     LEA    SysParam,A0
  231.     MOVEQ    #-1,D0
  232.     _WriteParam
  233.     PEA    NumberRect
  234.     _InValRect
  235.     Bra.S    Beep
  236.  
  237.  
  238. MyWindow:    DC.L    0        ; DA window pointer
  239. Coords:        DC.L    20<<16!10, 35<<16!19, 50<<16!27, 65<<16!37
  240. WindowRect:    DC.W    40,2,115,213    ; DA window rectangle
  241. NumberRect:    DC.W    38,175,50,190    ; DA number rectangle for invalrect
  242. ActivePend:    DC.W    0
  243. Chars:        DC.B    7        ; Mask for SPVolCtl
  244.         DC.B    '0'        ; Value to add to make ASCII
  245.         DC.W    ' '        ; <space> for setfontlock
  246.         DC.W    ' ©'        ;copyright symbol
  247.         DC.B    28,'1985 by William P. Steinberg'
  248.         DC.B    28,'Vers 1.3 - Free Distribution'
  249.         DC.B    23+1,'Current Volume Level = '
  250. ASCIIVol:    DC.B    0
  251.         DC.B    21,'Enter New Level (0-7)'
  252.  
  253.         END
  254.